<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <link rel="apple-touch-icon" sizes="76x76" href="{_INDEX_STATIC_}/moban/assets/img/apple-icon.png">
    <link rel="icon" type="image/png" href="{_INDEX_STATIC_}/moban/assets/img/favicon.png">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>首页 | {$system_name}</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
        name='viewport' />
    <link href="{_INDEX_STATIC_}/moban/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="{_INDEX_STATIC_}/moban/assets/css/now-ui-kit.css?v=1.1.0" rel="stylesheet" />
    <link href="{_INDEX_STATIC_}/moban/assets/css/font-awesome.min.css" rel="stylesheet" />
</head>

<body class="index-page sidebar-collapse">

    <!-- 引入导航栏 -->
    {include file='public/header'}

    <div class="container" style="min-height: 490px;">
        <!-- 个人信息 -->
        <div class="row">
            <div class="col-md-12">
                <h3>
                    修改一条纪录
                    <span style="font-size: 18px;color: red;">审核员：</span>
                    <span style="font-size: 18px;">{$achievement_info.audit_name | default='暂时未审核'}</span>
                </h3>
            </div>
        </div>

        <!-- 驳回理由 -->
        {if condition="$achievement_info.status == 3"}
        <div class="row">
            <div class="col-md-12">
                <div class="alert alert-warning">
                    <span style="font-size: 18px;">驳回理由： </span>
                    <strong style="font-size: 14px;">{$achievement_info.note}</strong>
                </div>
            </div>
        </div>
        {/if}

        <!-- 页面需要填写的内容 -->
        <div class="row">
            {volist name="classify_table_info.table_content.names" id="row" key="i"}
            <div class="col-md-6">
                <div class="input-group" id="app-add">
                    <span class="input-group-addon">{$row}&nbsp;&nbsp;</span>
                    {if
                    condition="$classify_type_list[$classify_table_info.table_content.selects[$i-1]-1]['name'] ==
                    '时间'"}
                    <input id="{$classify_table_info.table_content.cols[$i-1]}" type="date" class="form-control"
                        selects="{$classify_table_info.table_content.selects[$i-1]}"
                        value="{$achievement_info[$classify_table_info.table_content.cols[$i-1]] | date='Y-m-d'}">
                    {else /}
                    {if
                    condition="$classify_type_list[$classify_table_info.table_content.selects[$i-1]-1]['name'] ==
                    '数值'"}
                    <input id="{$classify_table_info.table_content.cols[$i-1]}" type="number" min="0.00" max="100.00"
                        step="0.1" class="form-control" selects="{$classify_table_info.table_content.selects[$i-1]}"
                        value="{$achievement_info[$classify_table_info.table_content.cols[$i-1]] / 100 | floatval}"
                        οnkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
                        onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
                    {else /}
                    <input id="{$classify_table_info.table_content.cols[$i-1]}" type="text" class="form-control"
                        placeholder="{$classify_table_info.table_content.notes[$i-1]}"
                        selects="{$classify_table_info.table_content.selects[$i-1]}"
                        value="{$achievement_info[$classify_table_info.table_content.cols[$i-1]]}">
                    {/if}
                    {/if}
                </div>
            </div>
            {/volist}
        </div>

        <!-- 按钮 -->
        <div class="row">
            <div class="col-md-6">
                <div class="col-md-6" style="text-align: center;">
                    <button id="save" class="btn btn-success btn-round btn-lg">点击修改</button>
                </div>
            </div>
            <div class="col-md-6">
                <div class="col-md-6" style="text-align: center;">
                    <button id="back" class="btn btn-info btn-round btn-lg">点击返回</button>
                </div>
            </div>
        </div>

    </div>
    <!-- 引入页脚 -->
    {include file='public/footer'}

    <script>

        // 点击修改
        $('#save').on('click', function () {
            var app_add = $('input');

            var data = [];
            for (var index = 0; index < app_add.length; index++) {
                var key = $(app_add[index]).attr('id');
                var value = $("#" + $(app_add[index]).attr("id")).val();
                var selects = $("#" + $(app_add[index]).attr("id")).attr('selects');

                data.push({
                    key: key,
                    value: value,
                    selects: selects
                });
            }

            $.ajax({
                url: "{:url('Achievement/edit')}",
                data: {
                    'data': data,
                    'pid': "{$pid}",
                    'id': "{$id}",
                },
                type: "POST",
                dataType: "JSON",
                async: true,
                success: function (res) {
                    // 返回结果处理
                    if (res.code == 0) {
                        return layer.msg(res.msg, { icon: 1, time: 900 }, function () {
                            location.reload()
                        });
                    } else {
                        return layer.msg(res.msg, { icon: 2, time: 900 });
                    }
                }
            });


        });

        // 点击返回
        $('#back').on('click', function () {
            redirect_url("{:url('Achievement/details')}?cid={$cid}");
        });

        // 重定向
        function redirect_url(url) {
            window.location.href = url;
        }
    </script>

</body>

</html>